package com.ihd.ihardware.view.lock.view;

import android.os.Bundle;

import com.ihd.ihardware.R;
import com.ihd.ihardware.common.AppConstans;
import com.ihd.ihardware.databinding.ActivityLockHisBinding;
import com.ihd.ihardware.pojo.DeviceListRes;
import com.ihd.ihardware.view.lock.viewmodel.LockRecoViewModel;

import cn.wowjoy.commonlibrary.base.BaseActivity;
import cn.wowjoy.commonlibrary.base.BaseConsumer;
import cn.wowjoy.commonlibrary.utils.DialogUtils;
import cn.wowjoy.commonlibrary.utils.ToastUtils;
import cn.wowjoy.commonlibrary.widget.MDialog;

public class LockHisActivity extends BaseActivity<ActivityLockHisBinding, LockRecoViewModel> {

    private MDialog waitDialog;
    private String equipmentId;

    @Override
    protected void init(Bundle savedInstanceState) {
        mImmersionBar.statusBarDarkFont(false).init();

        binding.mtitlebar.setLeftBack(this);
        binding.mtitlebar.setLeftImageResource(R.drawable.lock_nb_back);
        binding.mtitlebar.setTitle("开锁记录");
        binding.mtitlebar.setTitleColor(getResources().getColor(R.color.C_FFFFFF));

        equipmentId = getIntent().getStringExtra("equipmentId");

        binding.lockHisRV.setAdapter(viewModel.mLockHisAdapter);

        setRx(AppConstans.RECOLIST, new BaseConsumer<DeviceListRes>() {
            @Override
            protected void onStart() {
                waitDialog = DialogUtils.waitingDialog(LockHisActivity.this);
            }

            @Override
            protected void onSuccess(DeviceListRes mLiveData) {
                DialogUtils.dismiss(LockHisActivity.this);
                viewModel.setLockHis(mLiveData.getData().getList());
            }

            @Override
            protected void onError(Throwable error) {
                ToastUtils.showShort(LockHisActivity.this, error.getMessage());
                DialogUtils.dismiss(LockHisActivity.this);
            }
        });

        viewModel.lockRecordList(equipmentId);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_lock_his;
    }

    @Override
    protected Class getViewModelClass() {
        return LockRecoViewModel.class;
    }
}
